package springbook.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Aspect
public class TimeRecordAspect {

    @Around("execution(* springbook.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        //1.记录开始时间
        //2.执行目标方法
        //3.记录结束时间
        //4.记录耗时
        long start = System.currentTimeMillis();
        //执行目标方法
        Object result = joinPoint.proceed();
        log.info(joinPoint.getSignature()+"耗时："+(System.currentTimeMillis()-start)+"ms");
        return result;
    }
}
